package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface DishMapper {
    @Options(useGeneratedKeys = true,keyProperty = "id")
@Insert("insert into sky_take_out.dish(name, category_id, price, image, description, status, create_time, update_time, create_user, update_user) " +
        "values (#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(type = OperationType.INSERT)
    void save(Dish dish);

    @Select("select count(id) from sky_take_out.dish where category_id=#{categoryId}")
    Integer countByCategoryId(Long id);

    List<DishVO> pageId(DishPageQueryDTO dishPageQueryDTO);

    @Select("select * from sky_take_out.dish where id=#{id}")
    Dish getByid(Long id);
    @Delete("delete from dish where id=#{id}")
    void deleteId(Long id);
    @Select("select * from dish where id=#{id}")
    Dish selectid(Long id);
    @AutoFill(type = OperationType.UPDATE)
    void update(Dish dish);

    @Select("select * from dish where category_id=#{categoryId}")
    List<DishVO> list(Long categoryId);
    @Select("select d.* from dish d left join setmeal_dish s on d.id = s.dish_id where setmeal_id=#{id}")
    List<Dish> getsetmealId(Long id);

    List<Dish> dislist(Dish dish);
    @Select("select * from dish")
    List<Dish> getdishes();
}
